﻿using System.Collections.Generic;
using System.IO;
using UnityEngine;
using YunHao;

namespace UnknowWorld.CardGame
{
    /// <summary>
    /// 玩家数据
    /// </summary>
    [System.Serializable]
    public class Player : Character
    {
        /// <summary>
        /// 玩家职业
        /// </summary>
        public Profession Profession { get; set; }

        /// <summary>
        /// 加载初始卡组
        /// </summary>
        public void LoadInitCard(System.Action onFinish)
        {
            switch (Profession)
            {
                case Profession.Warriop:
                    string path = Path.Combine(Application.streamingAssetsPath, "Profession/Warriop.dat");
                    XmlControl.ReadXmlAsync<Player>(path, (player) => 
                    {
                        this.MaxHealth = player.MaxHealth;
                        this.Health = player.Health;
                        this.MaxMagic = player.MaxMagic;
                        this.Magic = player.Magic;
                        this.MaxStamina = player.MaxStamina;
                        this.Stamina = player.Stamina;
                        this.HandCardCount = player.HandCardCount;
                        this.Cards = new List<Card>();
                        foreach (var card in player.Cards)
                        {
                            var cd = CardPool.Instance.CardByKey(card.Key);
                            if (null != cd)
                            {
                                cd.Level = card.Level;
                                this.Cards.Add(cd);
                            }
                        }
                        if (null != onFinish) onFinish();
                    }, (err) => 
                    {
                        Debug.Log("Can`t found Warriop.dat");
                    });
                    break;
                case Profession.Mage:

                    break;
                case Profession.Hunter:

                    break;
            }
        }

    }

    /// <summary>
    /// 玩家职业
    /// </summary>
    public enum Profession
    {
        /// <summary>
        /// 战士
        /// </summary>
        Warriop, 
        /// <summary>
        /// 法师
        /// </summary>
        Mage, 
        /// <summary>
        /// 猎人
        /// </summary>
        Hunter 
    }
}